************************************ Creating Bartik Instruments - 6 topics *******************************************************

import delimited using "$folder/data/input/state_year_6_all_topics.csv", clear

rename conditional_list_provisions cond_list_prov
rename non_conditional_list_provisions non_cond_list_prov
rename contingent_provisions cont_prov
rename non_contingent_provision non_cont_prov
rename cond_provisions cond_prov
rename non_cond_provisions non_cond_prov

* Currently topics are vertical - must reshape into wide format
drop v1
reshape wide entitlement special_verb entitlement_verb permission permissive_modal neg obligation active_verb strict_modal constraint_value word_count conditional_count conditional conditional_list cond provision cont_prov cond_list_prov cond_prov non_cont_prov non_cond_list_prov non_cond_prov amend repeal, i(state year num_topics) j(topic)



* biennium includes stated year and previous year
gen biennium =  year + mod(year,2)
replace year = biennium

* Creating variables 

foreach x in 0 1 2 3 4 5  {

egen constr_obl`x'=rowtotal(constraint_value`x' obligation`x'), missing
egen permis_entit`x'=rowtotal(permission`x' entitlement`x'), missing

}
drop constraint_value* obligation* entitlement* permission*


* Collapsing to biennium level

collapse (mean) provision* word_count* cont_prov* cond_list_prov* cond_prov* non_cont_prov* non_cond_list_prov* non_cond_prov* constr_obl* permis_entit* special_verb* permissive_modal* neg* active_verb* strict_modal* amend* repeal*, by(state year)

* Setting time series

egen statefe = group(state)
gen statename1 = state
drop state
gen state = statefe

tsset statefe year, delta(2)

* Crating local macros for all variable combinations and categories

local variables provision0 - permis_entit5

local provisions provision0 - provision5

local words word_count0 - word_count5

local cont_prov cont_prov0 - cont_prov5

local cond_list_prov cond_list_prov0 - cond_list_prov5

local cond_prov cond_prov0 - cond_prov5

local non_cont_prov non_cont_prov0 - non_cont_prov5

local non_cond_list_prov non_cond_list_prov0 - non_cond_list_prov5

local non_cond_prov non_cond_prov0 - non_cond_prov5

local constraint_obligations constr_obl0 - constr_obl5

local permission_entitlements permis_entit0 - permis_entit5


* Replacing missing values with lags

foreach x of varlist `variables' {

replace `x' = L.`x' if missing(`x')
replace `x' = L2.`x' if missing(`x')
replace `x' = L3.`x' if missing(`x')
replace `x' = L4.`x' if missing(`x')
replace `x' = L5.`x' if missing(`x')
}

* Generating log and first difference of all variables

foreach x of varlist `variables' {

gen log_`x' = log(1+`x')
gen growth_6`x' = D.log_`x'

}

* Generating total growth by category-topic and growth in other states

foreach x of varlist  `variables' {

sort year 

by year: egen grow_sum_6`x' = total(growth_6`x')

by year: gen grow_loo_6`x' = (grow_sum_6`x' - growth_6`x') / 49

by year: gen grow_lo1_6`x' = (grow_sum_6`x') / 50

}

*Generating shares of each category and topic

egen provisions_6 = rowtotal(provision0 - provision5)
egen word_count_6 = rowtotal(word_count0 - word_count5)
egen cont_prov_6 = rowtotal(cont_prov0 - cont_prov5)
egen cond_list_prov_6 = rowtotal(cond_list_prov0 - cond_list_prov5)
egen cond_prov_6 = rowtotal(cond_prov0 - cond_prov5)
egen non_cont_prov_6 = rowtotal(non_cont_prov0 - non_cont_prov5)
egen non_cond_list_prov_6 = rowtotal(non_cond_list_prov0 - non_cond_list_prov5)
egen non_cond_prov_6 = rowtotal(non_cond_prov0 - non_cond_prov5)
egen constr_obl_6 = rowtotal(constr_obl0 - constr_obl5)
egen permis_entit_6 = rowtotal(permis_entit0 - permis_entit5)

foreach x of varlist `provisions' {
gen share6_`x' = `x' / provisions_6
}
foreach x of varlist `words' {
gen share6_`x' = `x' / word_count_6
}
foreach x of varlist `cont_prov' {
gen share6_`x' = `x' / cont_prov_6
}
foreach x of varlist `cond_list_prov' {
gen share6_`x' = `x' / cond_list_prov_6
}
foreach x of varlist `cond_prov' {
gen share6_`x' = `x' / cond_prov_6
}
foreach x of varlist `non_cont_prov' {
gen share6_`x' = `x' / non_cont_prov_6
}
foreach x of varlist `non_cond_list_prov' {
gen share6_`x' = `x' / non_cond_list_prov_6
}
foreach x of varlist `non_cond_prov' {
gen share6_`x' = `x' / non_cond_prov_6
}
foreach x of varlist `constraint_obligations' {
gen share6_`x' = `x' / constr_obl_6
}
foreach x of varlist `permission_entitlements' {
gen share6_`x' = `x' / permis_entit_6
}

* Generating average of initial 5 year share

sort statefe year
foreach x of varlist `variables' {

bys statefe: gen topic_in1_`x' = share6_`x'[1] 
bys statefe: gen topic_in2_`x' = share6_`x'[2] 
bys statefe: gen topic_in3_`x' = share6_`x'[3] 
bys statefe: gen topic_in4_`x' = share6_`x'[4] 
bys statefe: gen topic_in5_`x' = share6_`x'[5] 
bys statefe: gen topic_init_`x' = (topic_in1_`x' + topic_in2_`x'+topic_in3_`x'+topic_in4_`x'+topic_in5_`x')/5
}

* Generating Shocks for each category

foreach x of varlist `variables'{
gen shock_sum_6`x' =  topic_init_`x' * grow_loo_6`x'
gen shock_su1_6`x' =  topic_init_`x' * grow_lo1_6`x'

}


egen shk_summ6prov = rowtotal(shock_sum_6prov*)
egen shk_summ16prov = rowtotal(shock_su1_6prov*)

egen shk_summ6word = rowtotal(shock_sum_6word*)
egen shk_summ16word = rowtotal(shock_su1_6word*)

egen shk_summ6cont_prov = rowtotal(shock_sum_6cont_prov*)
egen shk_summ16cont_prov = rowtotal(shock_su1_6cont_prov*)

egen shk_summ6cond_list_prov = rowtotal(shock_sum_6cond_list_prov*)
egen shk_summ16cond_list_prov = rowtotal(shock_su1_6cond_list_prov*)

egen shk_summ6cond_prov = rowtotal(shock_sum_6cond_prov*)
egen shk_summ16cond_prov = rowtotal(shock_su1_6cond_prov*)

egen shk_summ6non_cont_prov = rowtotal(shock_sum_6non_cont_prov*)
egen shk_summ16non_cont_prov = rowtotal(shock_su1_6non_cont_prov*)

egen shk_summ6non_cond_list_prov = rowtotal(shock_sum_6non_cond_list_prov*)
egen shk_summ16non_cond_list_prov = rowtotal(shock_su1_6non_cond_list_prov*)

egen shk_summ6non_cond_prov = rowtotal(shock_sum_6non_cond_prov*)
egen shk_summ16non_cond_prov = rowtotal(shock_su1_6non_cond_prov*)

egen shk_summ6constr = rowtotal(shock_sum_6constr*)
egen shk_summ16constr = rowtotal(shock_su1_6constr*)

egen shk_summ6permis = rowtotal(shock_sum_6permis*)
egen shk_summ16permis = rowtotal(shock_su1_6permis*)


* / divide each category's shock by 6 topics
gen shock_prov_6 = shk_summ6prov/6
gen shock1_prov_6 = shk_summ16prov/6

gen shock_word_6 = shk_summ6word/6
gen shock1_word_6 = shk_summ16word/6

gen shock_cont_prov_6 = shk_summ6cont_prov/6
gen shock1_cont_prov_6 = shk_summ16cont_prov/6

gen shock_cond_list_prov_6 = shk_summ6cond_list_prov/6
gen shock1_cond_list_prov_6 = shk_summ16cond_list_prov/6

gen shock_cond_prov_6 = shk_summ6cond_prov/6
gen shock1_cond_prov_6 = shk_summ16cond_prov/6

gen shock_non_cont_prov_6 = shk_summ6non_cont_prov/6
gen shock1_non_cont_prov_6 = shk_summ16non_cont_prov/6

gen shock_non_cond_list_prov_6 = shk_summ6non_cond_list_prov/6
gen shock1_non_cond_list_prov_6 = shk_summ16non_cond_list_prov/6

gen shock_non_cond_prov_6 = shk_summ6non_cond_prov/6
gen shock1_non_cond_prov_6 = shk_summ16non_cond_prov/6

gen shock_constr_6 = shk_summ6constr/6
gen shock1_constr_6 = shk_summ16constr/6

gen shock_permis_6 = shk_summ6permis/6
gen shock1_permis_6 = shk_summ16permis/6
 


*Standardised Shocks
egen shock_prov6 = std(shock_prov_6)
egen shock_word6 = std(shock_word_6)
egen shock_cont_prov6 = std(shock_cont_prov_6)
egen shock_cond_list_prov6 = std(shock_cond_list_prov_6)
egen shock_cond_prov6 = std(shock_cond_prov_6)
egen shock_non_cont_prov6 = std(shock_non_cont_prov_6)
egen shock_non_cond_list_prov6 = std(shock_non_cond_list_prov_6)
egen shock_non_cond_prov6 = std(shock_non_cond_prov_6)
egen shock_constr6 = std(shock_constr_6)
egen shock_permis6 = std(shock_permis_6)


keep year statefe statename1 state provisions_* word_count_* cont_prov* cond_list_prov* cond_prov* non_cont_prov* non_cond_list_prov* non_cond_prov* constr_obl_* permis_entit_* share6* shock_prov6 - shock_permis6 growth_6provision* grow_sum_6provision*   share6_provision* growth_6provision*

save bartik_data_compl_6, replace

************************************ Creating Bartik Instruments - 12 topics *******************************************************

import delimited using "$folder/data/input/state_year_12_all_topics.csv", clear

rename conditional_list_provisions cond_list_prov
rename non_conditional_list_provisions non_cond_list_prov
rename contingent_provisions cont_prov
rename non_contingent_provision non_cont_prov
rename cond_provisions cond_prov
rename non_cond_provisions non_cond_prov

* Currently topics are vertical - must reshape into wide format
drop v1
reshape wide entitlement special_verb entitlement_verb permission permissive_modal neg obligation active_verb strict_modal constraint_value word_count conditional_count conditional conditional_list cond provision cont_prov cond_list_prov cond_prov non_cont_prov non_cond_list_prov non_cond_prov amend repeal, i(state year num_topics) j(topic)



* biennium includes stated year and previous year
gen biennium =  year + mod(year,2)
replace year = biennium

* Creating variables 

foreach x in 0 1 2 3 4 5 6 7 8 9 10 11 {

egen constr_obl`x'=rowtotal(constraint_value`x' obligation`x'), missing
egen permis_entit`x'=rowtotal(permission`x' entitlement`x'), missing

}
drop constraint_value* obligation* entitlement* permission*


* Collapsing to biennium level

collapse (mean) provision* word_count* cont_prov* cond_list_prov* cond_prov* non_cont_prov* non_cond_list_prov* non_cond_prov* constr_obl* permis_entit* special_verb* permissive_modal* neg* active_verb* strict_modal* amend* repeal*, by(state year)

* Setting time series

egen statefe = group(state)
gen statename1 = state
drop state
gen state = statefe

tsset statefe year, delta(2)

* Crating local macros for all variable combinations and categories

local variables provision0 - permis_entit11

local provisions provision0 - provision11

local words word_count0 - word_count11

local cont_prov cont_prov0 - cont_prov11

local cond_list_prov cond_list_prov0 - cond_list_prov11

local cond_prov cond_prov0 - cond_prov11

local non_cont_prov non_cont_prov0 - non_cont_prov11

local non_cond_list_prov non_cond_list_prov0 - non_cond_list_prov11

local non_cond_prov non_cond_prov0 - non_cond_prov11

local constraint_obligations constr_obl0 - constr_obl11

local permission_entitlements permis_entit0 - permis_entit11


* Replacing missing values with lags

foreach x of varlist `variables' {

replace `x' = L.`x' if missing(`x')
replace `x' = L2.`x' if missing(`x')
replace `x' = L3.`x' if missing(`x')
replace `x' = L4.`x' if missing(`x')
replace `x' = L5.`x' if missing(`x')
}

* Generating log and first difference of all variables

foreach x of varlist `variables' {

gen log_`x' = log(1+`x')
gen growth_12`x' = D.log_`x'

}

* Generating total growth by category-topic and growth in other states

foreach x of varlist  `variables' {

sort year 

by year: egen grow_sum_12`x' = total(growth_12`x')

by year: gen grow_loo_12`x' = (grow_sum_12`x' - growth_12`x') / 49

by year: gen grow_lo1_12`x' = (grow_sum_12`x') / 50

}

*Generating shares of each category and topic

egen provisions_12 = rowtotal(provision0 - provision11)
egen word_count_12 = rowtotal(word_count0 - word_count11)
egen cont_prov_12 = rowtotal(cont_prov0 - cont_prov11)
egen cond_list_prov_12 = rowtotal(cond_list_prov0 - cond_list_prov11)
egen cond_prov_12 = rowtotal(cond_prov0 - cond_prov11)
egen non_cont_prov_12 = rowtotal(non_cont_prov0 - non_cont_prov11)
egen non_cond_list_prov_12 = rowtotal(non_cond_list_prov0 - non_cond_list_prov11)
egen non_cond_prov_12 = rowtotal(non_cond_prov0 - non_cond_prov11)
egen constr_obl_12 = rowtotal(constr_obl0 - constr_obl11)
egen permis_entit_12 = rowtotal(permis_entit0 - permis_entit11)

foreach x of varlist `provisions' {
gen share12_`x' = `x' / provisions_12
}
foreach x of varlist `words' {
gen share12_`x' = `x' / word_count_12
}
foreach x of varlist `cont_prov' {
gen share12_`x' = `x' / cont_prov_12
}
foreach x of varlist `cond_list_prov' {
gen share12_`x' = `x' / cond_list_prov_12
}
foreach x of varlist `cond_prov' {
gen share12_`x' = `x' / cond_prov_12
}
foreach x of varlist `non_cont_prov' {
gen share12_`x' = `x' / non_cont_prov_12
}
foreach x of varlist `non_cond_list_prov' {
gen share12_`x' = `x' / non_cond_list_prov_12
}
foreach x of varlist `non_cond_prov' {
gen share12_`x' = `x' / non_cond_prov_12
}
foreach x of varlist `constraint_obligations' {
gen share12_`x' = `x' / constr_obl_12
}
foreach x of varlist `permission_entitlements' {
gen share12_`x' = `x' / permis_entit_12
}

* Generating average of initial 11 year share

sort statefe year
foreach x of varlist `variables' {

bys statefe: gen topic_in1_`x' = share12_`x'[1] 
bys statefe: gen topic_in2_`x' = share12_`x'[2] 
bys statefe: gen topic_in3_`x' = share12_`x'[3] 
bys statefe: gen topic_in4_`x' = share12_`x'[4] 
bys statefe: gen topic_in5_`x' = share12_`x'[5] 
bys statefe: gen topic_init_`x' = (topic_in1_`x' + topic_in2_`x'+topic_in3_`x'+topic_in4_`x'+topic_in5_`x')/5
}

* Generating Shocks for each category

foreach x of varlist `variables'{
gen shock_sum_12`x' =  topic_init_`x' * grow_loo_12`x'
gen shock_su1_12`x' =  topic_init_`x' * grow_lo1_12`x'

}


egen shk_summ12prov = rowtotal(shock_sum_12prov*)
egen shk_summ112prov = rowtotal(shock_su1_12prov*)

egen shk_summ12word = rowtotal(shock_sum_12word*)
egen shk_summ112word = rowtotal(shock_su1_12word*)

egen shk_summ12cont_prov = rowtotal(shock_sum_12cont_prov*)
egen shk_summ112cont_prov = rowtotal(shock_su1_12cont_prov*)

egen shk_summ12cond_list_prov = rowtotal(shock_sum_12cond_list_prov*)
egen shk_summ112cond_list_prov = rowtotal(shock_su1_12cond_list_prov*)

egen shk_summ12cond_prov = rowtotal(shock_sum_12cond_prov*)
egen shk_summ112cond_prov = rowtotal(shock_su1_12cond_prov*)

egen shk_summ12non_cont_prov = rowtotal(shock_sum_12non_cont_prov*)
egen shk_summ112non_cont_prov = rowtotal(shock_su1_12non_cont_prov*)

egen shk_summ12non_cond_list_prov = rowtotal(shock_sum_12non_cond_list_prov*)
egen shk_summ112non_cond_list_prov = rowtotal(shock_su1_12non_cond_list_prov*)

egen shk_summ12non_cond_prov = rowtotal(shock_sum_12non_cond_prov*)
egen shk_summ112non_cond_prov = rowtotal(shock_su1_12non_cond_prov*)

egen shk_summ12constr = rowtotal(shock_sum_12constr*)
egen shk_summ112constr = rowtotal(shock_su1_12constr*)

egen shk_summ12permis = rowtotal(shock_sum_12permis*)
egen shk_summ112permis = rowtotal(shock_su1_12permis*)


* / divide each category's shock by 12 topics
gen shock_prov_12 = shk_summ12prov/12
gen shock1_prov_12 = shk_summ112prov/12

gen shock_word_12 = shk_summ12word/12
gen shock1_word_12 = shk_summ112word/12

gen shock_cont_prov_12 = shk_summ12cont_prov/12
gen shock1_cont_prov_12 = shk_summ112cont_prov/12

gen shock_cond_list_prov_12 = shk_summ12cond_list_prov/12
gen shock1_cond_list_prov_12 = shk_summ112cond_list_prov/12

gen shock_cond_prov_12 = shk_summ12cond_prov/12
gen shock1_cond_prov_12 = shk_summ112cond_prov/12

gen shock_non_cont_prov_12 = shk_summ12non_cont_prov/12
gen shock1_non_cont_prov_12 = shk_summ112non_cont_prov/12

gen shock_non_cond_list_prov_12 = shk_summ12non_cond_list_prov/12
gen shock1_non_cond_list_prov_12 = shk_summ112non_cond_list_prov/12

gen shock_non_cond_prov_12 = shk_summ12non_cond_prov/12
gen shock1_non_cond_prov_12 = shk_summ112non_cond_prov/12

gen shock_constr_12 = shk_summ12constr/12
gen shock1_constr_12 = shk_summ112constr/12

gen shock_permis_12 = shk_summ12permis/12
gen shock1_permis_12 = shk_summ112permis/12
 

*Standardised Shocks
egen shock_prov12 = std(shock_prov_12)
egen shock_word12 = std(shock_word_12)
egen shock_cont_prov12 = std(shock_cont_prov_12)
egen shock_cond_list_prov12 = std(shock_cond_list_prov_12)
egen shock_cond_prov12 = std(shock_cond_prov_12)
egen shock_non_cont_prov12 = std(shock_non_cont_prov_12)
egen shock_non_cond_list_prov12 = std(shock_non_cond_list_prov_12)
egen shock_non_cond_prov12 = std(shock_non_cond_prov_12)
egen shock_constr12 = std(shock_constr_12)
egen shock_permis12 = std(shock_permis_12)


keep year statefe statename1 state provisions_* word_count_* cont_prov* cond_list_prov* cond_prov* non_cont_prov* non_cond_list_prov* non_cond_prov* constr_obl_* permis_entit_* share12* shock_prov12 - shock_permis12 growth_12provision* grow_sum_12provision*   share12_provision* growth_12provision*

save bartik_data_compl_12, replace


************************************ Creating Bartik Instruments - 18 topics *******************************************************


import delimited using "$folder/data/input/state_year_18_all_topics.csv", clear

rename conditional_list_provisions cond_list_prov
rename non_conditional_list_provisions non_cond_list_prov
rename contingent_provisions cont_prov
rename non_contingent_provision non_cont_prov
rename cond_provisions cond_prov
rename non_cond_provisions non_cond_prov

* Currently topics are vertical - must reshape into wide format
drop v1
reshape wide entitlement special_verb entitlement_verb permission permissive_modal neg obligation active_verb strict_modal constraint_value word_count conditional_count conditional conditional_list cond provision cont_prov cond_list_prov cond_prov non_cont_prov non_cond_list_prov non_cond_prov amend repeal, i(state year num_topics) j(topic)



* biennium includes stated year and previous year
gen biennium =  year + mod(year,2)
replace year = biennium

* Creating variables 

foreach x in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17  {

egen constr_obl`x'=rowtotal(constraint_value`x' obligation`x'), missing
egen permis_entit`x'=rowtotal(permission`x' entitlement`x'), missing

}
drop constraint_value* obligation* entitlement* permission*


* Collapsing to biennium level

collapse (mean) provision* word_count* cont_prov* cond_list_prov* cond_prov* non_cont_prov* non_cond_list_prov* non_cond_prov* constr_obl* permis_entit* special_verb* permissive_modal* neg* active_verb* strict_modal* amend* repeal*, by(state year)

* Setting time series

egen statefe = group(state)
gen statename1 = state
drop state
gen state = statefe

tsset statefe year, delta(2)

* Crating local macros for all variable combinations and categories

local variables provision0 - permis_entit17

local provisions provision0 - provision17

local words word_count0 - word_count17

local cont_prov cont_prov0 - cont_prov17

local cond_list_prov cond_list_prov0 - cond_list_prov17

local cond_prov cond_prov0 - cond_prov17

local non_cont_prov non_cont_prov0 - non_cont_prov17

local non_cond_list_prov non_cond_list_prov0 - non_cond_list_prov17

local non_cond_prov non_cond_prov0 - non_cond_prov17

local constraint_obligations constr_obl0 - constr_obl17

local permission_entitlements permis_entit0 - permis_entit17


* Replacing missing values with lags

foreach x of varlist `variables' {

replace `x' = L.`x' if missing(`x')
replace `x' = L2.`x' if missing(`x')
replace `x' = L3.`x' if missing(`x')
replace `x' = L4.`x' if missing(`x')
replace `x' = L5.`x' if missing(`x')
}

* Generating log and first difference of all variables

foreach x of varlist `variables' {

gen log_`x' = log(1+`x')
gen growth_18`x' = D.log_`x'

}

* Generating total growth by category-topic and growth in other states

foreach x of varlist  `variables' {

sort year 

by year: egen grow_sum_18`x' = total(growth_18`x')

by year: gen grow_loo_18`x' = (grow_sum_18`x' - growth_18`x') / 49

by year: gen grow_lo1_18`x' = (grow_sum_18`x') / 50

}


foreach x of varlist provision0 - provision17 {

sort year 

by year: egen growth_sum_18`x' = total(growth_18`x')

by year: gen growth_loo_18`x' = (growth_sum_18`x' - growth_18`x') / 49

by year: gen growth_loo1_18`x' = (growth_sum_18`x') / 50

}

*Generating shares of each category and topic

egen provisions_18 = rowtotal(provision0 - provision17)
egen word_count_18 = rowtotal(word_count0 - word_count17)
egen cont_prov_18 = rowtotal(cont_prov0 - cont_prov17)
egen cond_list_prov_18 = rowtotal(cond_list_prov0 - cond_list_prov17)
egen cond_prov_18 = rowtotal(cond_prov0 - cond_prov17)
egen non_cont_prov_18 = rowtotal(non_cont_prov0 - non_cont_prov17)
egen non_cond_list_prov_18 = rowtotal(non_cond_list_prov0 - non_cond_list_prov17)
egen non_cond_prov_18 = rowtotal(non_cond_prov0 - non_cond_prov17)
egen constr_obl_18 = rowtotal(constr_obl0 - constr_obl17)
egen permis_entit_18 = rowtotal(permis_entit0 - permis_entit17)

foreach x of varlist `provisions' {
gen share18_`x' = `x' / provisions_18
}
foreach x of varlist `words' {
gen share18_`x' = `x' / word_count_18
}
foreach x of varlist `cont_prov' {
gen share18_`x' = `x' / cont_prov_18
}
foreach x of varlist `cond_list_prov' {
gen share18_`x' = `x' / cond_list_prov_18
}
foreach x of varlist `cond_prov' {
gen share18_`x' = `x' / cond_prov_18
}
foreach x of varlist `non_cont_prov' {
gen share18_`x' = `x' / non_cont_prov_18
}
foreach x of varlist `non_cond_list_prov' {
gen share18_`x' = `x' / non_cond_list_prov_18
}
foreach x of varlist `non_cond_prov' {
gen share18_`x' = `x' / non_cond_prov_18
}
foreach x of varlist `constraint_obligations' {
gen share18_`x' = `x' / constr_obl_18
}
foreach x of varlist `permission_entitlements' {
gen share18_`x' = `x' / permis_entit_18
}

* Generating average of initial 17 year share

sort statefe year
foreach x of varlist `variables' {

bys statefe: gen topic_in1_`x' = share18_`x'[1] 
bys statefe: gen topic_in2_`x' = share18_`x'[2] 
bys statefe: gen topic_in3_`x' = share18_`x'[3] 
bys statefe: gen topic_in4_`x' = share18_`x'[4] 
bys statefe: gen topic_in5_`x' = share18_`x'[5] 
bys statefe: gen topic_init_`x' = (topic_in1_`x' + topic_in2_`x'+topic_in3_`x'+topic_in4_`x'+topic_in5_`x')/5
}

* Generating Shocks for each category

foreach x of varlist `variables'{
gen shock_sum_18`x' =  topic_init_`x' * grow_loo_18`x'
gen shock_su1_18`x' =  topic_init_`x' * grow_lo1_18`x'

}


egen shk_summ18prov = rowtotal(shock_sum_18prov*)
egen shk_summ118prov = rowtotal(shock_su1_18prov*)

egen shk_summ18word = rowtotal(shock_sum_18word*)
egen shk_summ118word = rowtotal(shock_su1_18word*)

egen shk_summ18cont_prov = rowtotal(shock_sum_18cont_prov*)
egen shk_summ118cont_prov = rowtotal(shock_su1_18cont_prov*)

egen shk_summ18cond_list_prov = rowtotal(shock_sum_18cond_list_prov*)
egen shk_summ118cond_list_prov = rowtotal(shock_su1_18cond_list_prov*)

egen shk_summ18cond_prov = rowtotal(shock_sum_18cond_prov*)
egen shk_summ118cond_prov = rowtotal(shock_su1_18cond_prov*)

egen shk_summ18non_cont_prov = rowtotal(shock_sum_18non_cont_prov*)
egen shk_summ118non_cont_prov = rowtotal(shock_su1_18non_cont_prov*)

egen shk_summ18non_cond_list_prov = rowtotal(shock_sum_18non_cond_list_prov*)
egen shk_summ118non_cond_list_prov = rowtotal(shock_su1_18non_cond_list_prov*)

egen shk_summ18non_cond_prov = rowtotal(shock_sum_18non_cond_prov*)
egen shk_summ118non_cond_prov = rowtotal(shock_su1_18non_cond_prov*)

egen shk_summ18constr = rowtotal(shock_sum_18constr*)
egen shk_summ118constr = rowtotal(shock_su1_18constr*)

egen shk_summ18permis = rowtotal(shock_sum_18permis*)
egen shk_summ118permis = rowtotal(shock_su1_18permis*)


* / divide each category's shock by 18 topics
gen shock_prov_18 = shk_summ18prov/18
gen shock1_prov_18 = shk_summ118prov/18

gen shock_word_18 = shk_summ18word/18
gen shock1_word_18 = shk_summ118word/18

gen shock_cont_prov_18 = shk_summ18cont_prov/18
gen shock1_cont_prov_18 = shk_summ118cont_prov/18

gen shock_cond_list_prov_18 = shk_summ18cond_list_prov/18
gen shock1_cond_list_prov_18 = shk_summ118cond_list_prov/18

gen shock_cond_prov_18 = shk_summ18cond_prov/18
gen shock1_cond_prov_18 = shk_summ118cond_prov/18

gen shock_non_cont_prov_18 = shk_summ18non_cont_prov/18
gen shock1_non_cont_prov_18 = shk_summ118non_cont_prov/18

gen shock_non_cond_list_prov_18 = shk_summ18non_cond_list_prov/18
gen shock1_non_cond_list_prov_18 = shk_summ118non_cond_list_prov/18

gen shock_non_cond_prov_18 = shk_summ18non_cond_prov/18
gen shock1_non_cond_prov_18 = shk_summ118non_cond_prov/18

gen shock_constr_18 = shk_summ18constr/18
gen shock1_constr_18 = shk_summ118constr/18

gen shock_permis_18 = shk_summ18permis/18
gen shock1_permis_18 = shk_summ118permis/18
 

*Standardised Shocks
egen shock_prov18 = std(shock_prov_18)
egen shock_word18 = std(shock_word_18)
egen shock_cont_prov18 = std(shock_cont_prov_18)
egen shock_cond_list_prov18 = std(shock_cond_list_prov_18)
egen shock_cond_prov18 = std(shock_cond_prov_18)
egen shock_non_cont_prov18 = std(shock_non_cont_prov_18)
egen shock_non_cond_list_prov18 = std(shock_non_cond_list_prov_18)
egen shock_non_cond_prov18 = std(shock_non_cond_prov_18)
egen shock_constr18 = std(shock_constr_18)
egen shock_permis18 = std(shock_permis_18)


************************************ Creating Bartik Instruments - 18 topics with levels *******************************************************


* Generating average of initial 17 year levels

sort statefe year
foreach x of varlist `variables' {

bys statefe: gen topic_in1_`x'_l = `x'[1] 
bys statefe: gen topic_in2_`x'_l = `x'[2] 
bys statefe: gen topic_in3_`x'_l = `x'[3] 
bys statefe: gen topic_in4_`x'_l = `x'[4] 
bys statefe: gen topic_in5_`x'_l = `x'[5] 
bys statefe: gen topic_in_`x'_l = (topic_in1_`x'_l + topic_in2_`x'_l+topic_in3_`x'_l+topic_in4_`x'_l+topic_in5_`x'_l)/5
}

* Generating Shocks for each category

foreach x of varlist `variables'{
gen sh_sm_18`x'_l =  topic_in_`x'_l * grow_loo_18`x'

}


egen shk_summ18prov_l = rowtotal(sh_sm_18prov*)
egen shk_summ18cond_l = rowtotal(sh_sm_18cond*)
egen shk_summ18noncond_l = rowtotal(sh_sm_18non_cond*)


* / divide each category's shock by 18 topics
gen shock_prov_18_l = shk_summ18prov_l/18
gen shock_cond_18_l = shk_summ18cond_l/18
gen shock_noncond_18_l = shk_summ18noncond_l/18

*Standardised Shocks

egen shock_prov18_l = std(shock_prov_18_l)
egen shock_condlist_prov18_l = std(shock_cond_18_l)
egen shock_noncondlist_prov18_l = std(shock_noncond_18_l)


************************************Add First Principal Component*************************************************************************
pca topic_init_provision*

predict pc1_compl18, score


foreach var of varlist `provisions' {
rename `var' `var'_18
}


keep year statefe statename1 state growth_sum_18provision* log_provision* provisions_* word_count_* cont_prov* cond_list_prov* cond_prov* non_cont_prov* non_cond_list_prov* non_cond_prov* constr_obl_* permis_entit_* share18* shock_prov18 - shock_permis18 growth_18provision* grow_sum_18provision* topic_init_provision*  share18_provision* growth_18provision* pc1_compl18 shock_prov18_l shock_condlist_prov18_l shock_noncondlist_prov18_l

save bartik_data_compl_18, replace


************************************ Creating Bartik Instruments - 24 topics *******************************************************


import delimited using "$folder/data/input/state_year_24_all_topics.csv", clear

rename conditional_list_provisions cond_list_prov
rename non_conditional_list_provisions non_cond_list_prov
rename contingent_provisions cont_prov
rename non_contingent_provision non_cont_prov
rename cond_provisions cond_prov
rename non_cond_provisions non_cond_prov

* Currently topics are vertical - must reshape into wide format
drop v1
reshape wide entitlement special_verb entitlement_verb permission permissive_modal neg obligation active_verb strict_modal constraint_value word_count conditional_count conditional conditional_list cond provision cont_prov cond_list_prov cond_prov non_cont_prov non_cond_list_prov non_cond_prov amend repeal, i(state year num_topics) j(topic)



* biennium includes stated year and previous year
gen biennium =  year + mod(year,2)
replace year = biennium

* Creating variables 

foreach x in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23  {

egen constr_obl`x'=rowtotal(constraint_value`x' obligation`x'), missing
egen permis_entit`x'=rowtotal(permission`x' entitlement`x'), missing

}
drop constraint_value* obligation* entitlement* permission*


* Collapsing to biennium level

collapse (mean) provision* word_count* cont_prov* cond_list_prov* cond_prov* non_cont_prov* non_cond_list_prov* non_cond_prov* constr_obl* permis_entit* special_verb* permissive_modal* neg* active_verb* strict_modal* amend* repeal*, by(state year)

* Setting time series

egen statefe = group(state)
gen statename1 = state
drop state
gen state = statefe

tsset statefe year, delta(2)

* Crating local macros for all variable combinations and categories

local variables provision0 - permis_entit23

local provisions provision0 - provision23

local words word_count0 - word_count23

local cont_prov cont_prov0 - cont_prov23

local cond_list_prov cond_list_prov0 - cond_list_prov23

local cond_prov cond_prov0 - cond_prov23

local non_cont_prov non_cont_prov0 - non_cont_prov23

local non_cond_list_prov non_cond_list_prov0 - non_cond_list_prov23

local non_cond_prov non_cond_prov0 - non_cond_prov23

local constraint_obligations constr_obl0 - constr_obl23

local permission_entitlements permis_entit0 - permis_entit23


* Replacing missing values with lags

foreach x of varlist `variables' {

replace `x' = L.`x' if missing(`x')
replace `x' = L2.`x' if missing(`x')
replace `x' = L3.`x' if missing(`x')
replace `x' = L4.`x' if missing(`x')
replace `x' = L5.`x' if missing(`x')
}

* Generating log and first difference of all variables

foreach x of varlist `variables' {

gen log_`x' = log(1+`x')
gen growth_24`x' = D.log_`x'

}

* Generating total growth by category-topic and growth in other states

foreach x of varlist  `variables' {

sort year 

by year: egen grow_sum_24`x' = total(growth_24`x')

by year: gen grow_loo_24`x' = (grow_sum_24`x' - growth_24`x') / 49

by year: gen grow_lo1_24`x' = (grow_sum_24`x') / 50

}

*Generating shares of each category and topic

egen provisions_24 = rowtotal(provision0 - provision23)
egen word_count_24 = rowtotal(word_count0 - word_count23)
egen cont_prov_24 = rowtotal(cont_prov0 - cont_prov23)
egen cond_list_prov_24 = rowtotal(cond_list_prov0 - cond_list_prov23)
egen cond_prov_24 = rowtotal(cond_prov0 - cond_prov23)
egen non_cont_prov_24 = rowtotal(non_cont_prov0 - non_cont_prov23)
egen non_cond_list_prov_24 = rowtotal(non_cond_list_prov0 - non_cond_list_prov23)
egen non_cond_prov_24 = rowtotal(non_cond_prov0 - non_cond_prov23)
egen constr_obl_24 = rowtotal(constr_obl0 - constr_obl23)
egen permis_entit_24 = rowtotal(permis_entit0 - permis_entit23)

foreach x of varlist `provisions' {
gen share24_`x' = `x' / provisions_24
}
foreach x of varlist `words' {
gen share24_`x' = `x' / word_count_24
}
foreach x of varlist `cont_prov' {
gen share24_`x' = `x' / cont_prov_24
}
foreach x of varlist `cond_list_prov' {
gen share24_`x' = `x' / cond_list_prov_24
}
foreach x of varlist `cond_prov' {
gen share24_`x' = `x' / cond_prov_24
}
foreach x of varlist `non_cont_prov' {
gen share24_`x' = `x' / non_cont_prov_24
}
foreach x of varlist `non_cond_list_prov' {
gen share24_`x' = `x' / non_cond_list_prov_24
}
foreach x of varlist `non_cond_prov' {
gen share24_`x' = `x' / non_cond_prov_24
}
foreach x of varlist `constraint_obligations' {
gen share24_`x' = `x' / constr_obl_24
}
foreach x of varlist `permission_entitlements' {
gen share24_`x' = `x' / permis_entit_24
}

* Generating average of initial 23 year share

sort statefe year
foreach x of varlist `variables' {

bys statefe: gen topic_in1_`x' = share24_`x'[1] 
bys statefe: gen topic_in2_`x' = share24_`x'[2] 
bys statefe: gen topic_in3_`x' = share24_`x'[3] 
bys statefe: gen topic_in4_`x' = share24_`x'[4] 
bys statefe: gen topic_in5_`x' = share24_`x'[5] 
bys statefe: gen topic_init_`x' = (topic_in1_`x' + topic_in2_`x'+topic_in3_`x'+topic_in4_`x'+topic_in5_`x')/5
}

* Generating Shocks for each category

foreach x of varlist `variables'{
gen shock_sum_24`x' =  topic_init_`x' * grow_loo_24`x'
gen shock_su1_24`x' =  topic_init_`x' * grow_lo1_24`x'

}


egen shk_summ24prov = rowtotal(shock_sum_24prov*)
egen shk_summ232prov = rowtotal(shock_su1_24prov*)

egen shk_summ24word = rowtotal(shock_sum_24word*)
egen shk_summ232word = rowtotal(shock_su1_24word*)

egen shk_summ24cont_prov = rowtotal(shock_sum_24cont_prov*)
egen shk_summ232cont_prov = rowtotal(shock_su1_24cont_prov*)

egen shk_summ24cond_list_prov = rowtotal(shock_sum_24cond_list_prov*)
egen shk_summ232cond_list_prov = rowtotal(shock_su1_24cond_list_prov*)

egen shk_summ24cond_prov = rowtotal(shock_sum_24cond_prov*)
egen shk_summ232cond_prov = rowtotal(shock_su1_24cond_prov*)

egen shk_summ24non_cont_prov = rowtotal(shock_sum_24non_cont_prov*)
egen shk_summ232non_cont_prov = rowtotal(shock_su1_24non_cont_prov*)

egen shk_summ24non_cond_list_prov = rowtotal(shock_sum_24non_cond_list_prov*)
egen shk_summ232non_cond_list_prov = rowtotal(shock_su1_24non_cond_list_prov*)

egen shk_summ24non_cond_prov = rowtotal(shock_sum_24non_cond_prov*)
egen shk_summ232non_cond_prov = rowtotal(shock_su1_24non_cond_prov*)

egen shk_summ24constr = rowtotal(shock_sum_24constr*)
egen shk_summ232constr = rowtotal(shock_su1_24constr*)

egen shk_summ24permis = rowtotal(shock_sum_24permis*)
egen shk_summ232permis = rowtotal(shock_su1_24permis*)


* / divide each category's shock by 24 topics
gen shock_prov_24 = shk_summ24prov/24
gen shock1_prov_24 = shk_summ232prov/24

gen shock_word_24 = shk_summ24word/24
gen shock1_word_24 = shk_summ232word/24

gen shock_cont_prov_24 = shk_summ24cont_prov/24
gen shock1_cont_prov_24 = shk_summ232cont_prov/24

gen shock_cond_list_prov_24 = shk_summ24cond_list_prov/24
gen shock1_cond_list_prov_24 = shk_summ232cond_list_prov/24

gen shock_cond_prov_24 = shk_summ24cond_prov/24
gen shock1_cond_prov_24 = shk_summ232cond_prov/24

gen shock_non_cont_prov_24 = shk_summ24non_cont_prov/24
gen shock1_non_cont_prov_24 = shk_summ232non_cont_prov/24

gen shock_non_cond_list_prov_24 = shk_summ24non_cond_list_prov/24
gen shock1_non_cond_list_prov_24 = shk_summ232non_cond_list_prov/24

gen shock_non_cond_prov_24 = shk_summ24non_cond_prov/24
gen shock1_non_cond_prov_24 = shk_summ232non_cond_prov/24

gen shock_constr_24 = shk_summ24constr/24
gen shock1_constr_24 = shk_summ232constr/24

gen shock_permis_24 = shk_summ24permis/24
gen shock1_permis_24 = shk_summ232permis/24
 


*Standardised Shocks
egen shock_prov24 = std(shock_prov_24)
egen shock_word24 = std(shock_word_24)
egen shock_cont_prov24 = std(shock_cont_prov_24)
egen shock_cond_list_prov24 = std(shock_cond_list_prov_24)
egen shock_cond_prov24 = std(shock_cond_prov_24)
egen shock_non_cont_prov24 = std(shock_non_cont_prov_24)
egen shock_non_cond_list_prov24 = std(shock_non_cond_list_prov_24)
egen shock_non_cond_prov24 = std(shock_non_cond_prov_24)
egen shock_constr24 = std(shock_constr_24)
egen shock_permis24 = std(shock_permis_24)


keep year statefe statename1 state provisions_* word_count_* cont_prov* cond_list_prov* cond_prov* non_cont_prov* non_cond_list_prov* non_cond_prov* constr_obl_* permis_entit_* share24* shock_prov24 - shock_permis24 growth_24provision* grow_sum_24provision*   share24_provision* growth_24provision*

save bartik_data_compl_24, replace

************************************ Creating Bartik Instruments - 30 topics *******************************************************

import delimited using "$folder/data/input/state_year_30_all_topics.csv", clear

rename conditional_list_provisions cond_list_prov
rename non_conditional_list_provisions non_cond_list_prov
rename contingent_provisions cont_prov
rename non_contingent_provision non_cont_prov
rename cond_provisions cond_prov
rename non_cond_provisions non_cond_prov

* Currently topics are vertical - must reshape into wide format
drop v1
reshape wide entitlement special_verb entitlement_verb permission permissive_modal neg obligation active_verb strict_modal constraint_value word_count conditional_count conditional conditional_list cond provision cont_prov cond_list_prov cond_prov non_cont_prov non_cond_list_prov non_cond_prov amend repeal, i(state year num_topics) j(topic)



* biennium includes stated year and previous year
gen biennium =  year + mod(year,2)
replace year = biennium

* Creating variables 

foreach x in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 {

egen constr_obl`x'=rowtotal(constraint_value`x' obligation`x'), missing
egen permis_entit`x'=rowtotal(permission`x' entitlement`x'), missing

}
drop constraint_value* obligation* entitlement* permission*


* Collapsing to biennium level

collapse (mean) provision* word_count* cont_prov* cond_list_prov* cond_prov* non_cont_prov* non_cond_list_prov* non_cond_prov* constr_obl* permis_entit* special_verb* permissive_modal* neg* active_verb* strict_modal* amend* repeal*, by(state year)

* Setting time series

egen statefe = group(state)
gen statename1 = state
drop state
gen state = statefe

tsset statefe year, delta(2)

* Crating local macros for all variable combinations and categories

local variables provision0 - permis_entit29

local provisions provision0 - provision29

local words word_count0 - word_count29

local cont_prov cont_prov0 - cont_prov29

local cond_list_prov cond_list_prov0 - cond_list_prov29

local cond_prov cond_prov0 - cond_prov29

local non_cont_prov non_cont_prov0 - non_cont_prov29

local non_cond_list_prov non_cond_list_prov0 - non_cond_list_prov29

local non_cond_prov non_cond_prov0 - non_cond_prov29

local constraint_obligations constr_obl0 - constr_obl29

local permission_entitlements permis_entit0 - permis_entit29


* Replacing missing values with lags

foreach x of varlist `variables' {

replace `x' = L.`x' if missing(`x')
replace `x' = L2.`x' if missing(`x')
replace `x' = L3.`x' if missing(`x')
replace `x' = L4.`x' if missing(`x')
replace `x' = L5.`x' if missing(`x')
}

* Generating log and first difference of all variables

foreach x of varlist `variables' {

gen log_`x' = log(1+`x')
gen growth_30`x' = D.log_`x'

}

* Generating total growth by category-topic and growth in other states

foreach x of varlist  `variables' {

sort year 

by year: egen grow_sum_30`x' = total(growth_30`x')

by year: gen grow_loo_30`x' = (grow_sum_30`x' - growth_30`x') / 49

by year: gen grow_lo1_30`x' = (grow_sum_30`x') / 50

}

*Generating shares of each category and topic

egen provisions_30 = rowtotal(provision0 - provision29)
egen word_count_30 = rowtotal(word_count0 - word_count29)
egen cont_prov_30 = rowtotal(cont_prov0 - cont_prov29)
egen cond_list_prov_30 = rowtotal(cond_list_prov0 - cond_list_prov29)
egen cond_prov_30 = rowtotal(cond_prov0 - cond_prov29)
egen non_cont_prov_30 = rowtotal(non_cont_prov0 - non_cont_prov29)
egen non_cond_list_prov_30 = rowtotal(non_cond_list_prov0 - non_cond_list_prov29)
egen non_cond_prov_30 = rowtotal(non_cond_prov0 - non_cond_prov29)
egen constr_obl_30 = rowtotal(constr_obl0 - constr_obl29)
egen permis_entit_30 = rowtotal(permis_entit0 - permis_entit29)

foreach x of varlist `provisions' {
gen share30_`x' = `x' / provisions_30
}
foreach x of varlist `words' {
gen share30_`x' = `x' / word_count_30
}
foreach x of varlist `cont_prov' {
gen share30_`x' = `x' / cont_prov_30
}
foreach x of varlist `cond_list_prov' {
gen share30_`x' = `x' / cond_list_prov_30
}
foreach x of varlist `cond_prov' {
gen share30_`x' = `x' / cond_prov_30
}
foreach x of varlist `non_cont_prov' {
gen share30_`x' = `x' / non_cont_prov_30
}
foreach x of varlist `non_cond_list_prov' {
gen share30_`x' = `x' / non_cond_list_prov_30
}
foreach x of varlist `non_cond_prov' {
gen share30_`x' = `x' / non_cond_prov_30
}
foreach x of varlist `constraint_obligations' {
gen share30_`x' = `x' / constr_obl_30
}
foreach x of varlist `permission_entitlements' {
gen share30_`x' = `x' / permis_entit_30
}

* Generating average of initial 29 year share

sort statefe year
foreach x of varlist `variables' {

bys statefe: gen topic_in1_`x' = share30_`x'[1] 
bys statefe: gen topic_in2_`x' = share30_`x'[2] 
bys statefe: gen topic_in3_`x' = share30_`x'[3] 
bys statefe: gen topic_in4_`x' = share30_`x'[4] 
bys statefe: gen topic_in5_`x' = share30_`x'[5] 
bys statefe: gen topic_init_`x' = (topic_in1_`x' + topic_in2_`x'+topic_in3_`x'+topic_in4_`x'+topic_in5_`x')/5
}

* Generating Shocks for each category

foreach x of varlist `variables'{
gen shock_sum_30`x' =  topic_init_`x' * grow_loo_30`x'
gen shock_su1_30`x' =  topic_init_`x' * grow_lo1_30`x'

}


egen shk_summ30prov = rowtotal(shock_sum_30prov*)
egen shk_summ292prov = rowtotal(shock_su1_30prov*)

egen shk_summ30word = rowtotal(shock_sum_30word*)
egen shk_summ292word = rowtotal(shock_su1_30word*)

egen shk_summ30cont_prov = rowtotal(shock_sum_30cont_prov*)
egen shk_summ292cont_prov = rowtotal(shock_su1_30cont_prov*)

egen shk_summ30cond_list_prov = rowtotal(shock_sum_30cond_list_prov*)
egen shk_summ292cond_list_prov = rowtotal(shock_su1_30cond_list_prov*)

egen shk_summ30cond_prov = rowtotal(shock_sum_30cond_prov*)
egen shk_summ292cond_prov = rowtotal(shock_su1_30cond_prov*)

egen shk_summ30non_cont_prov = rowtotal(shock_sum_30non_cont_prov*)
egen shk_summ292non_cont_prov = rowtotal(shock_su1_30non_cont_prov*)

egen shk_summ30non_cond_list_prov = rowtotal(shock_sum_30non_cond_list_prov*)
egen shk_summ292non_cond_list_prov = rowtotal(shock_su1_30non_cond_list_prov*)

egen shk_summ30non_cond_prov = rowtotal(shock_sum_30non_cond_prov*)
egen shk_summ292non_cond_prov = rowtotal(shock_su1_30non_cond_prov*)

egen shk_summ30constr = rowtotal(shock_sum_30constr*)
egen shk_summ292constr = rowtotal(shock_su1_30constr*)

egen shk_summ30permis = rowtotal(shock_sum_30permis*)
egen shk_summ292permis = rowtotal(shock_su1_30permis*)


* / divide each category's shock by 30 topics
gen shock_prov_30 = shk_summ30prov/30
gen shock1_prov_30 = shk_summ292prov/30

gen shock_word_30 = shk_summ30word/30
gen shock1_word_30 = shk_summ292word/30

gen shock_cont_prov_30 = shk_summ30cont_prov/30
gen shock1_cont_prov_30 = shk_summ292cont_prov/30

gen shock_cond_list_prov_30 = shk_summ30cond_list_prov/30
gen shock1_cond_list_prov_30 = shk_summ292cond_list_prov/30

gen shock_cond_prov_30 = shk_summ30cond_prov/30
gen shock1_cond_prov_30 = shk_summ292cond_prov/30

gen shock_non_cont_prov_30 = shk_summ30non_cont_prov/30
gen shock1_non_cont_prov_30 = shk_summ292non_cont_prov/30

gen shock_non_cond_list_prov_30 = shk_summ30non_cond_list_prov/30
gen shock1_non_cond_list_prov_30 = shk_summ292non_cond_list_prov/30

gen shock_non_cond_prov_30 = shk_summ30non_cond_prov/30
gen shock1_non_cond_prov_30 = shk_summ292non_cond_prov/30

gen shock_constr_30 = shk_summ30constr/30
gen shock1_constr_30 = shk_summ292constr/30

gen shock_permis_30 = shk_summ30permis/30
gen shock1_permis_30 = shk_summ292permis/30
 

*Standardised Shocks
egen shock_prov30 = std(shock_prov_30)
egen shock_word30 = std(shock_word_30)
egen shock_cont_prov30 = std(shock_cont_prov_30)
egen shock_cond_list_prov30 = std(shock_cond_list_prov_30)
egen shock_cond_prov30 = std(shock_cond_prov_30)
egen shock_non_cont_prov30 = std(shock_non_cont_prov_30)
egen shock_non_cond_list_prov30 = std(shock_non_cond_list_prov_30)
egen shock_non_cond_prov30 = std(shock_non_cond_prov_30)
egen shock_constr30 = std(shock_constr_30)
egen shock_permis30 = std(shock_permis_30)


keep year statefe statename1 state provisions_* word_count_* cont_prov* cond_list_prov* cond_prov* non_cont_prov* non_cond_list_prov* non_cond_prov* constr_obl_* permis_entit_* share30* shock_prov30 - shock_permis30 growth_30provision* grow_sum_30provision*   share30_provision* growth_30provision*

save bartik_data_compl_30, replace

************************************ Creating Bartik Instruments - 36 topics *******************************************************

import delimited using "$folder/data/input/state_year_36_all_topics.csv", clear

rename conditional_list_provisions cond_list_prov
rename non_conditional_list_provisions non_cond_list_prov
rename contingent_provisions cont_prov
rename non_contingent_provision non_cont_prov
rename cond_provisions cond_prov
rename non_cond_provisions non_cond_prov

* Currently topics are vertical - must reshape into wide format
drop v1
reshape wide entitlement special_verb entitlement_verb permission permissive_modal neg obligation active_verb strict_modal constraint_value word_count conditional_count conditional conditional_list cond provision cont_prov cond_list_prov cond_prov non_cont_prov non_cond_list_prov non_cond_prov amend repeal, i(state year num_topics) j(topic)



* biennium includes stated year and previous year
gen biennium =  year + mod(year,2)
replace year = biennium

* Creating variables 

foreach x in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 {

egen constr_obl`x'=rowtotal(constraint_value`x' obligation`x'), missing
egen permis_entit`x'=rowtotal(permission`x' entitlement`x'), missing

}
drop constraint_value* obligation* entitlement* permission*


* Collapsing to biennium level

collapse (mean) provision* word_count* cont_prov* cond_list_prov* cond_prov* non_cont_prov* non_cond_list_prov* non_cond_prov* constr_obl* permis_entit* special_verb* permissive_modal* neg* active_verb* strict_modal* amend* repeal*, by(state year)

* Setting time series

egen statefe = group(state)
gen statename1 = state
drop state
gen state = statefe

tsset statefe year, delta(2)

* Crating local macros for all variable combinations and categories

local variables provision0 - permis_entit35

local provisions provision0 - provision35

local words word_count0 - word_count35

local cont_prov cont_prov0 - cont_prov35

local cond_list_prov cond_list_prov0 - cond_list_prov35

local cond_prov cond_prov0 - cond_prov35

local non_cont_prov non_cont_prov0 - non_cont_prov35

local non_cond_list_prov non_cond_list_prov0 - non_cond_list_prov35

local non_cond_prov non_cond_prov0 - non_cond_prov35

local constraint_obligations constr_obl0 - constr_obl35

local permission_entitlements permis_entit0 - permis_entit35


* Replacing missing values with lags

foreach x of varlist `variables' {

replace `x' = L.`x' if missing(`x')
replace `x' = L2.`x' if missing(`x')
replace `x' = L3.`x' if missing(`x')
replace `x' = L4.`x' if missing(`x')
replace `x' = L5.`x' if missing(`x')
}

* Generating log and first difference of all variables

foreach x of varlist `variables' {

gen log_`x' = log(1+`x')
gen growth_36`x' = D.log_`x'

}

* Generating total growth by category-topic and growth in other states

foreach x of varlist  `variables' {

sort year 

by year: egen grow_sum_36`x' = total(growth_36`x')

by year: gen grow_loo_36`x' = (grow_sum_36`x' - growth_36`x') / 49

by year: gen grow_lo1_36`x' = (grow_sum_36`x') / 50

}

*Generating shares of each category and topic

egen provisions_36 = rowtotal(provision0 - provision35)
egen word_count_36 = rowtotal(word_count0 - word_count35)
egen cont_prov_36 = rowtotal(cont_prov0 - cont_prov35)
egen cond_list_prov_36 = rowtotal(cond_list_prov0 - cond_list_prov35)
egen cond_prov_36 = rowtotal(cond_prov0 - cond_prov35)
egen non_cont_prov_36 = rowtotal(non_cont_prov0 - non_cont_prov35)
egen non_cond_list_prov_36 = rowtotal(non_cond_list_prov0 - non_cond_list_prov35)
egen non_cond_prov_36 = rowtotal(non_cond_prov0 - non_cond_prov35)
egen constr_obl_36 = rowtotal(constr_obl0 - constr_obl35)
egen permis_entit_36 = rowtotal(permis_entit0 - permis_entit35)

foreach x of varlist `provisions' {
gen share36_`x' = `x' / provisions_36
}
foreach x of varlist `words' {
gen share36_`x' = `x' / word_count_36
}
foreach x of varlist `cont_prov' {
gen share36_`x' = `x' / cont_prov_36
}
foreach x of varlist `cond_list_prov' {
gen share36_`x' = `x' / cond_list_prov_36
}
foreach x of varlist `cond_prov' {
gen share36_`x' = `x' / cond_prov_36
}
foreach x of varlist `non_cont_prov' {
gen share36_`x' = `x' / non_cont_prov_36
}
foreach x of varlist `non_cond_list_prov' {
gen share36_`x' = `x' / non_cond_list_prov_36
}
foreach x of varlist `non_cond_prov' {
gen share36_`x' = `x' / non_cond_prov_36
}
foreach x of varlist `constraint_obligations' {
gen share36_`x' = `x' / constr_obl_36
}
foreach x of varlist `permission_entitlements' {
gen share36_`x' = `x' / permis_entit_36
}

* Generating average of initial 35 year share

sort statefe year
foreach x of varlist `variables' {

bys statefe: gen topic_in1_`x' = share36_`x'[1] 
bys statefe: gen topic_in2_`x' = share36_`x'[2] 
bys statefe: gen topic_in3_`x' = share36_`x'[3] 
bys statefe: gen topic_in4_`x' = share36_`x'[4] 
bys statefe: gen topic_in5_`x' = share36_`x'[5] 
bys statefe: gen topic_init_`x' = (topic_in1_`x' + topic_in2_`x'+topic_in3_`x'+topic_in4_`x'+topic_in5_`x')/5
}

* Generating Shocks for each category

foreach x of varlist `variables'{
gen shock_sum_36`x' =  topic_init_`x' * grow_loo_36`x'
gen shock_su1_36`x' =  topic_init_`x' * grow_lo1_36`x'

}


egen shk_summ36prov = rowtotal(shock_sum_36prov*)
egen shk_summ352prov = rowtotal(shock_su1_36prov*)

egen shk_summ36word = rowtotal(shock_sum_36word*)
egen shk_summ352word = rowtotal(shock_su1_36word*)

egen shk_summ36cont_prov = rowtotal(shock_sum_36cont_prov*)
egen shk_summ352cont_prov = rowtotal(shock_su1_36cont_prov*)

egen shk_summ36cond_list_prov = rowtotal(shock_sum_36cond_list_prov*)
egen shk_summ352cond_list_prov = rowtotal(shock_su1_36cond_list_prov*)

egen shk_summ36cond_prov = rowtotal(shock_sum_36cond_prov*)
egen shk_summ352cond_prov = rowtotal(shock_su1_36cond_prov*)

egen shk_summ36non_cont_prov = rowtotal(shock_sum_36non_cont_prov*)
egen shk_summ352non_cont_prov = rowtotal(shock_su1_36non_cont_prov*)

egen shk_summ36non_cond_list_prov = rowtotal(shock_sum_36non_cond_list_prov*)
egen shk_summ352non_cond_list_prov = rowtotal(shock_su1_36non_cond_list_prov*)

egen shk_summ36non_cond_prov = rowtotal(shock_sum_36non_cond_prov*)
egen shk_summ352non_cond_prov = rowtotal(shock_su1_36non_cond_prov*)

egen shk_summ36constr = rowtotal(shock_sum_36constr*)
egen shk_summ352constr = rowtotal(shock_su1_36constr*)

egen shk_summ36permis = rowtotal(shock_sum_36permis*)
egen shk_summ352permis = rowtotal(shock_su1_36permis*)


* / divide each category's shock by 36 topics
gen shock_prov_36 = shk_summ36prov/36
gen shock1_prov_36 = shk_summ352prov/36

gen shock_word_36 = shk_summ36word/36
gen shock1_word_36 = shk_summ352word/36

gen shock_cont_prov_36 = shk_summ36cont_prov/36
gen shock1_cont_prov_36 = shk_summ352cont_prov/36

gen shock_cond_list_prov_36 = shk_summ36cond_list_prov/36
gen shock1_cond_list_prov_36 = shk_summ352cond_list_prov/36

gen shock_cond_prov_36 = shk_summ36cond_prov/36
gen shock1_cond_prov_36 = shk_summ352cond_prov/36

gen shock_non_cont_prov_36 = shk_summ36non_cont_prov/36
gen shock1_non_cont_prov_36 = shk_summ352non_cont_prov/36

gen shock_non_cond_list_prov_36 = shk_summ36non_cond_list_prov/36
gen shock1_non_cond_list_prov_36 = shk_summ352non_cond_list_prov/36

gen shock_non_cond_prov_36 = shk_summ36non_cond_prov/36
gen shock1_non_cond_prov_36 = shk_summ352non_cond_prov/36

gen shock_constr_36 = shk_summ36constr/36
gen shock1_constr_36 = shk_summ352constr/36

gen shock_permis_36 = shk_summ36permis/36
gen shock1_permis_36 = shk_summ352permis/36
 

*Standardised Shocks
egen shock_prov36 = std(shock_prov_36)
egen shock_word36 = std(shock_word_36)
egen shock_cont_prov36 = std(shock_cont_prov_36)
egen shock_cond_list_prov36 = std(shock_cond_list_prov_36)
egen shock_cond_prov36 = std(shock_cond_prov_36)
egen shock_non_cont_prov36 = std(shock_non_cont_prov_36)
egen shock_non_cond_list_prov36 = std(shock_non_cond_list_prov_36)
egen shock_non_cond_prov36 = std(shock_non_cond_prov_36)
egen shock_constr36 = std(shock_constr_36)
egen shock_permis36 = std(shock_permis_36)


keep year statefe statename1 state provisions_* word_count_* cont_prov* cond_list_prov* cond_prov* non_cont_prov* non_cond_list_prov* non_cond_prov* constr_obl_* permis_entit_* share36* shock_prov36 - shock_permis36 growth_36provision* grow_sum_36provision*   share36_provision* growth_36provision*

save bartik_data_compl_36, replace

************************************ Creating Bartik Instruments - 42 topics *******************************************************

import delimited using "$folder/data/input/state_year_42_all_topics.csv", clear

rename conditional_list_provisions cond_list_prov
rename non_conditional_list_provisions non_cond_list_prov
rename contingent_provisions cont_prov
rename non_contingent_provision non_cont_prov
rename cond_provisions cond_prov
rename non_cond_provisions non_cond_prov

* Currently topics are vertical - must reshape into wide format
drop v1
reshape wide entitlement special_verb entitlement_verb permission permissive_modal neg obligation active_verb strict_modal constraint_value word_count conditional_count conditional conditional_list cond provision cont_prov cond_list_prov cond_prov non_cont_prov non_cond_list_prov non_cond_prov amend repeal, i(state year num_topics) j(topic)

* biennium includes stated year and previous year
gen biennium =  year + mod(year,2)
replace year = biennium

* Creating variables 

foreach x in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 {

egen constr_obl`x'=rowtotal(constraint_value`x' obligation`x'), missing
egen permis_entit`x'=rowtotal(permission`x' entitlement`x'), missing

}
drop constraint_value* obligation* entitlement* permission*


* Collapsing to biennium level

collapse (mean) provision* word_count* cont_prov* cond_list_prov* cond_prov* non_cont_prov* non_cond_list_prov* non_cond_prov* constr_obl* permis_entit* special_verb* permissive_modal* neg* active_verb* strict_modal* amend* repeal*, by(state year)

* Setting time series

egen statefe = group(state)
gen statename1 = state
drop state
gen state = statefe

tsset statefe year, delta(2)

* Crating local macros for all variable combinations and categories

local variables provision0 - permis_entit41

local provisions provision0 - provision41

local words word_count0 - word_count41

local cont_prov cont_prov0 - cont_prov41

local cond_list_prov cond_list_prov0 - cond_list_prov41

local cond_prov cond_prov0 - cond_prov41

local non_cont_prov non_cont_prov0 - non_cont_prov41

local non_cond_list_prov non_cond_list_prov0 - non_cond_list_prov41

local non_cond_prov non_cond_prov0 - non_cond_prov41

local constraint_obligations constr_obl0 - constr_obl41

local permission_entitlements permis_entit0 - permis_entit41


* Replacing missing values with lags

foreach x of varlist `variables' {

replace `x' = L.`x' if missing(`x')
replace `x' = L2.`x' if missing(`x')
replace `x' = L3.`x' if missing(`x')
replace `x' = L4.`x' if missing(`x')
replace `x' = L5.`x' if missing(`x')
}

* Generating log and first difference of all variables

foreach x of varlist `variables' {

gen log_`x' = log(1+`x')
gen growth_42`x' = D.log_`x'

}

* Generating total growth by category-topic and growth in other states

foreach x of varlist  `variables' {

sort year 

by year: egen grow_sum_42`x' = total(growth_42`x')

by year: gen grow_loo_42`x' = (grow_sum_42`x' - growth_42`x') / 49

by year: gen grow_lo1_42`x' = (grow_sum_42`x') / 50

}

*Generating shares of each category and topic

egen provisions_42 = rowtotal(provision0 - provision41)
egen word_count_42 = rowtotal(word_count0 - word_count41)
egen cont_prov_42 = rowtotal(cont_prov0 - cont_prov41)
egen cond_list_prov_42 = rowtotal(cond_list_prov0 - cond_list_prov41)
egen cond_prov_42 = rowtotal(cond_prov0 - cond_prov41)
egen non_cont_prov_42 = rowtotal(non_cont_prov0 - non_cont_prov41)
egen non_cond_list_prov_42 = rowtotal(non_cond_list_prov0 - non_cond_list_prov41)
egen non_cond_prov_42 = rowtotal(non_cond_prov0 - non_cond_prov41)
egen constr_obl_42 = rowtotal(constr_obl0 - constr_obl41)
egen permis_entit_42 = rowtotal(permis_entit0 - permis_entit41)

foreach x of varlist `provisions' {
gen share42_`x' = `x' / provisions_42
}
foreach x of varlist `words' {
gen share42_`x' = `x' / word_count_42
}
foreach x of varlist `cont_prov' {
gen share42_`x' = `x' / cont_prov_42
}
foreach x of varlist `cond_list_prov' {
gen share42_`x' = `x' / cond_list_prov_42
}
foreach x of varlist `cond_prov' {
gen share42_`x' = `x' / cond_prov_42
}
foreach x of varlist `non_cont_prov' {
gen share42_`x' = `x' / non_cont_prov_42
}
foreach x of varlist `non_cond_list_prov' {
gen share42_`x' = `x' / non_cond_list_prov_42
}
foreach x of varlist `non_cond_prov' {
gen share42_`x' = `x' / non_cond_prov_42
}
foreach x of varlist `constraint_obligations' {
gen share42_`x' = `x' / constr_obl_42
}
foreach x of varlist `permission_entitlements' {
gen share42_`x' = `x' / permis_entit_42
}

* Generating average of initial 41 year share

sort statefe year
foreach x of varlist `variables' {

bys statefe: gen topic_in1_`x' = share42_`x'[1] 
bys statefe: gen topic_in2_`x' = share42_`x'[2] 
bys statefe: gen topic_in3_`x' = share42_`x'[3] 
bys statefe: gen topic_in4_`x' = share42_`x'[4] 
bys statefe: gen topic_in5_`x' = share42_`x'[5] 
bys statefe: gen topic_init_`x' = (topic_in1_`x' + topic_in2_`x'+topic_in3_`x'+topic_in4_`x'+topic_in5_`x')/5
}

* Generating Shocks for each category

foreach x of varlist `variables'{
gen shock_sum_42`x' =  topic_init_`x' * grow_loo_42`x'
gen shock_su1_42`x' =  topic_init_`x' * grow_lo1_42`x'

}


egen shk_summ42prov = rowtotal(shock_sum_42prov*)
egen shk_summ412prov = rowtotal(shock_su1_42prov*)

egen shk_summ42word = rowtotal(shock_sum_42word*)
egen shk_summ412word = rowtotal(shock_su1_42word*)

egen shk_summ42cont_prov = rowtotal(shock_sum_42cont_prov*)
egen shk_summ412cont_prov = rowtotal(shock_su1_42cont_prov*)

egen shk_summ42cond_list_prov = rowtotal(shock_sum_42cond_list_prov*)
egen shk_summ412cond_list_prov = rowtotal(shock_su1_42cond_list_prov*)

egen shk_summ42cond_prov = rowtotal(shock_sum_42cond_prov*)
egen shk_summ412cond_prov = rowtotal(shock_su1_42cond_prov*)

egen shk_summ42non_cont_prov = rowtotal(shock_sum_42non_cont_prov*)
egen shk_summ412non_cont_prov = rowtotal(shock_su1_42non_cont_prov*)

egen shk_summ42non_cond_list_prov = rowtotal(shock_sum_42non_cond_list_prov*)
egen shk_summ412non_cond_list_prov = rowtotal(shock_su1_42non_cond_list_prov*)

egen shk_summ42non_cond_prov = rowtotal(shock_sum_42non_cond_prov*)
egen shk_summ412non_cond_prov = rowtotal(shock_su1_42non_cond_prov*)

egen shk_summ42constr = rowtotal(shock_sum_42constr*)
egen shk_summ412constr = rowtotal(shock_su1_42constr*)

egen shk_summ42permis = rowtotal(shock_sum_42permis*)
egen shk_summ412permis = rowtotal(shock_su1_42permis*)


* / divide each category's shock by 42 topics
gen shock_prov_42 = shk_summ42prov/42
gen shock1_prov_42 = shk_summ412prov/42

gen shock_word_42 = shk_summ42word/42
gen shock1_word_42 = shk_summ412word/42

gen shock_cont_prov_42 = shk_summ42cont_prov/42
gen shock1_cont_prov_42 = shk_summ412cont_prov/42

gen shock_cond_list_prov_42 = shk_summ42cond_list_prov/42
gen shock1_cond_list_prov_42 = shk_summ412cond_list_prov/42

gen shock_cond_prov_42 = shk_summ42cond_prov/42
gen shock1_cond_prov_42 = shk_summ412cond_prov/42

gen shock_non_cont_prov_42 = shk_summ42non_cont_prov/42
gen shock1_non_cont_prov_42 = shk_summ412non_cont_prov/42

gen shock_non_cond_list_prov_42 = shk_summ42non_cond_list_prov/42
gen shock1_non_cond_list_prov_42 = shk_summ412non_cond_list_prov/42

gen shock_non_cond_prov_42 = shk_summ42non_cond_prov/42
gen shock1_non_cond_prov_42 = shk_summ412non_cond_prov/42

gen shock_constr_42 = shk_summ42constr/42
gen shock1_constr_42 = shk_summ412constr/42

gen shock_permis_42 = shk_summ42permis/42
gen shock1_permis_42 = shk_summ412permis/42
 

*Standardised Shocks
egen shock_prov42 = std(shock_prov_42)
egen shock_word42 = std(shock_word_42)
egen shock_cont_prov42 = std(shock_cont_prov_42)
egen shock_cond_list_prov42 = std(shock_cond_list_prov_42)
egen shock_cond_prov42 = std(shock_cond_prov_42)
egen shock_non_cont_prov42 = std(shock_non_cont_prov_42)
egen shock_non_cond_list_prov42 = std(shock_non_cond_list_prov_42)
egen shock_non_cond_prov42 = std(shock_non_cond_prov_42)
egen shock_constr42 = std(shock_constr_42)
egen shock_permis42 = std(shock_permis_42)


keep year statefe statename1 state provisions_* word_count_* cont_prov* cond_list_prov* cond_prov* non_cont_prov* non_cond_list_prov* non_cond_prov* constr_obl_* permis_entit_* share42* shock_prov42 - shock_permis42 growth_42provision* grow_sum_42provision*   share42_provision* growth_42provision*

save bartik_data_compl_42, replace


******************************* Creating Bartik Instruments - 42 topics by group **************************************************

import delimited using "$folder/data/input/state_year_42_all_topics.csv", clear

rename conditional_list_provisions cond_list_prov
rename non_conditional_list_provisions non_cond_list_prov
rename contingent_provisions cont_prov
rename non_contingent_provision non_cont_prov
rename cond_provisions cond_prov
rename non_cond_provisions non_cond_prov

merge m:1 topic using "$folder/data/input/42_groups"
drop _merge


replace category="econ" if category=="economic"
replace category="soc" if category=="social"
replace category="fisc" if category=="fiscal"
replace category="proc" if category=="procedural"
save bartik_42_groups, replace


foreach y in econ fisc misc proc soc {

use bartik_42_groups, clear

keep if category == "`y'"

* Currently topics are vertical - must reshape into wide format
drop v1 label
reshape wide entitlement special_verb entitlement_verb permission permissive_modal neg obligation active_verb strict_modal constraint_value word_count conditional_count conditional conditional_list cond provision cont_prov cond_list_prov cond_prov non_cont_prov non_cond_list_prov non_cond_prov amend repeal, i(state year num_topics) j(topic)


* biennium includes stated year and previous year
gen biennium =  year + mod(year,2)
replace year = biennium

* Creating variables 
local econ 0 2 4 5 8 17 24 29 30 32 33 35 36 37 39 41
local fisc 1 6 12 18 20 23 27 28
local soc 7 9 14 21 25 34 38
local proc 3 10 13 15 16 19 22 26 31 40
local misc 11

foreach x of local `y' {

egen constr_obl`x'=rowtotal(constraint_value`x' obligation`x'), missing
egen permis_entit`x'=rowtotal(permission`x' entitlement`x'), missing

}
drop constraint_value* obligation* entitlement* permission*


* Collapsing to biennium level

collapse (mean) provision* word_count* cont_prov* cond_list_prov* cond_prov* non_cont_prov* non_cond_list_prov* non_cond_prov* constr_obl* permis_entit* special_verb* permissive_modal* neg* active_verb* strict_modal* amend* repeal*, by(state year)

* Setting time series

egen statefe = group(state)
gen statename1 = state
drop state
gen state = statefe

tsset statefe year, delta(2)

* Crating local macros for all variable combinations and categories

if "`y'"=="fisc" {
local variables provision1 - permis_entit28
local provisions provision1 - provision28
local words word_count1 - word_count28
local cont_prov cont_prov1 - cont_prov28
local cond_list_prov cond_list_prov1 - cond_list_prov28
local cond_prov cond_prov1 - cond_prov28
local non_cont_prov non_cont_prov1 - non_cont_prov28
local non_cond_list_prov non_cond_list_prov1 - non_cond_list_prov28
local non_cond_prov non_cond_prov1 - non_cond_prov28
local constraint_obligations constr_obl1 - constr_obl28
local permission_entitlements permis_entit1 - permis_entit28
}

if "`y'"=="econ" {
local variables provision0 - permis_entit41
local provisions provision0 - provision41
local words word_count0 - word_count41
local cont_prov cont_prov0 - cont_prov41
local cond_list_prov cond_list_prov0 - cond_list_prov41
local cond_prov cond_prov0 - cond_prov41
local non_cont_prov non_cont_prov0 - non_cont_prov41
local non_cond_list_prov non_cond_list_prov0 - non_cond_list_prov41
local non_cond_prov non_cond_prov0 - non_cond_prov41
local constraint_obligations constr_obl0 - constr_obl41
local permission_entitlements permis_entit0 - permis_entit41
}

if "`y'"=="soc" {
local variables provision7 - permis_entit38
local provisions provision7 - provision38
local words word_count7 - word_count38
local cont_prov cont_prov7 - cont_prov38
local cond_list_prov cond_list_prov7 - cond_list_prov38
local cond_prov cond_prov7 - cond_prov38
local non_cont_prov non_cont_prov7 - non_cont_prov38
local non_cond_list_prov non_cond_list_prov7 - non_cond_list_prov38
local non_cond_prov non_cond_prov7 - non_cond_prov38
local constraint_obligations constr_obl7 - constr_obl38
local permission_entitlements permis_entit7 - permis_entit38
}

if "`y'"=="proc" {
local variables provision3 - permis_entit40
local provisions provision3 - provision40
local words word_count3 - word_count40
local cont_prov cont_prov3 - cont_prov40
local cond_list_prov cond_list_prov3 - cond_list_prov40
local cond_prov cond_prov3 - cond_prov40
local non_cont_prov non_cont_prov3 - non_cont_prov40
local non_cond_list_prov non_cond_list_prov3 - non_cond_list_prov40
local non_cond_prov non_cond_prov3 - non_cond_prov40
local constraint_obligations constr_obl3 - constr_obl40
local permission_entitlements permis_entit3 - permis_entit40
}

if "`y'"=="misc" {
local variables provision11 - permis_entit11
local provisions provision11
local words word_count11
local cont_prov cont_prov11
local cond_list_prov cond_list_prov11
local cond_prov cond_prov11
local non_cont_prov non_cont_prov11
local non_cond_list_prov non_cond_list_prov11
local non_cond_prov non_cond_prov11
local constraint_obligations constr_obl11
local permission_entitlements permis_entit11
}

* Replacing missing values with lags

foreach x of varlist `variables' {

replace `x' = L.`x' if missing(`x')
replace `x' = L2.`x' if missing(`x')
replace `x' = L3.`x' if missing(`x')
replace `x' = L4.`x' if missing(`x')
replace `x' = L5.`x' if missing(`x')
}

* Generating log and first difference of all variables

foreach x of varlist `variables' {

gen log_`x' = log(1+`x')
gen growth_42`x' = D.log_`x'

}

* Generating total growth by category-topic and growth in other states

if "`y'"=="fisc" {
foreach x of varlist  `variables' {

sort year 

by year: egen grow_sum_42`x' = total(growth_42`x')

by year: gen grow_loo_42`x' = (grow_sum_42`x' - growth_42`x') / 49

by year: gen grow_lo1_42`x' = (grow_sum_42`x') / 50

}
}
if "`y'"=="econ" {
foreach x of varlist  `variables' {

sort year 

by year: egen grow_sum_42`x' = total(growth_42`x')

by year: gen grow_loo_42`x' = (grow_sum_42`x' - growth_42`x') / 49

by year: gen grow_lo1_42`x' = (grow_sum_42`x') / 50

}
}
if "`y'"=="soc" {
foreach x of varlist  `variables' {

sort year 

by year: egen grow_sum_42`x' = total(growth_42`x')

by year: gen grow_loo_42`x' = (grow_sum_42`x' - growth_42`x') / 49

by year: gen grow_lo1_42`x' = (grow_sum_42`x') / 50

}
}
if "`y'"=="proc" {
foreach x of varlist  `variables' {

sort year 

by year: egen grow_sum_42`x' = total(growth_42`x')

by year: gen grow_loo_42`x' = (grow_sum_42`x' - growth_42`x') / 49

by year: gen grow_lo1_42`x' = (grow_sum_42`x') / 50

}
}
if "`y'"=="misc" {
foreach x of varlist  `variables' {

sort year 

by year: egen grow_sum_42`x' = total(growth_42`x')

by year: gen grow_loo_42`x' = (grow_sum_42`x' - growth_42`x') / 49

by year: gen grow_lo1_42`x' = (grow_sum_42`x') / 50

}
}

*Generating shares of each category and topic

egen provisions_42`y' = rowtotal(provision*)
egen word_count_42`y' = rowtotal(word_count*)
egen cont_prov_42`y' = rowtotal(cont_prov*)
egen cond_list_42`y' = rowtotal(cond_list_prov*)
egen cond_prov_42`y' = rowtotal(cond_prov*)
egen non_cont_prov_42`y' = rowtotal(non_cont_prov*)
egen non_cond_list_42`y' = rowtotal(non_cond_list_prov*)
egen non_cond_prov_42`y' = rowtotal(non_cond_prov*)
egen constr_obl_42`y' = rowtotal(constr_obl*)
egen permis_entit_42`y' = rowtotal(permis_entit*)

foreach x of varlist `provisions' {
gen share`y'_`x' = `x' / provisions_42`y'
}
foreach x of varlist `words' {
gen share`y'_`x' = `x' / word_count_42`y'
}
foreach x of varlist `cont_prov' {
gen share`y'_`x' = `x' / cont_prov_42`y'
}
foreach x of varlist `cond_list_prov' {
gen share`y'_`x' = `x' / cond_list_42`y'
}
foreach x of varlist `cond_prov' {
gen share`y'_`x' = `x' / cond_prov_42`y'
}
foreach x of varlist `non_cont_prov' {
gen share`y'_`x' = `x' / non_cont_prov_42`y'
}
foreach x of varlist `non_cond_list_prov' {
gen share`y'_`x' = `x' / non_cond_list_42`y'
}
foreach x of varlist `non_cond_prov' {
gen share`y'_`x' = `x' / non_cond_prov_42`y'
}
foreach x of varlist `constraint_obligations' {
gen share`y'_`x' = `x' / constr_obl_42`y'
}
foreach x of varlist `permission_entitlements' {
gen share`y'_`x' = `x' / permis_entit_42`y'
}

* Generating average of initial 41 year share

sort statefe year
foreach x of varlist `variables' {

bys statefe: gen topic_in1_`x' = share`y'_`x'[1] 
bys statefe: gen topic_in2_`x' = share`y'_`x'[2] 
bys statefe: gen topic_in3_`x' = share`y'_`x'[3] 
bys statefe: gen topic_in4_`x' = share`y'_`x'[4] 
bys statefe: gen topic_in5_`x' = share`y'_`x'[5] 
bys statefe: gen top_in`y'_`x' = (topic_in1_`x' + topic_in2_`x'+topic_in3_`x'+topic_in4_`x'+topic_in5_`x')/5
}

* Generating Shocks for each category

foreach x of varlist `variables'{
gen shock_sum_42`x' =  top_in`y'_`x' * grow_loo_42`x'
gen shock_su1_42`x' =  top_in`y'_`x' * grow_lo1_42`x'

}


egen shk_summ42prov = rowtotal(shock_sum_42prov*)
egen shk_summ412prov = rowtotal(shock_su1_42prov*)

egen shk_summ42word = rowtotal(shock_sum_42word*)
egen shk_summ412word = rowtotal(shock_su1_42word*)

egen shk_summ42cont_prov = rowtotal(shock_sum_42cont_prov*)
egen shk_summ412cont_prov = rowtotal(shock_su1_42cont_prov*)

egen shk_summ42cond_list_prov = rowtotal(shock_sum_42cond_list_prov*)
egen shk_summ412cond_list_prov = rowtotal(shock_su1_42cond_list_prov*)

egen shk_summ42cond_prov = rowtotal(shock_sum_42cond_prov*)
egen shk_summ412cond_prov = rowtotal(shock_su1_42cond_prov*)

egen shk_summ42non_cont_prov = rowtotal(shock_sum_42non_cont_prov*)
egen shk_summ412non_cont_prov = rowtotal(shock_su1_42non_cont_prov*)

egen shk_summ42non_cond_list_prov = rowtotal(shock_sum_42non_cond_list_prov*)
egen shk_summ412non_cond_list_prov = rowtotal(shock_su1_42non_cond_list_prov*)

egen shk_summ42non_cond_prov = rowtotal(shock_sum_42non_cond_prov*)
egen shk_summ412non_cond_prov = rowtotal(shock_su1_42non_cond_prov*)

egen shk_summ42constr = rowtotal(shock_sum_42constr*)
egen shk_summ412constr = rowtotal(shock_su1_42constr*)

egen shk_summ42permis = rowtotal(shock_sum_42permis*)
egen shk_summ412permis = rowtotal(shock_su1_42permis*)


* / divide each category's shock by 42 topics
if "`y'"=="econ" {
gen shock_prov_42 = shk_summ42prov/15
gen shock1_prov_42 = shk_summ412prov/16

gen shock_word_42 = shk_summ42word/15
gen shock1_word_42 = shk_summ412word/16

gen shock_cont_prov_42 = shk_summ42cont_prov/15
gen shock1_cont_prov_42 = shk_summ412cont_prov/16

gen shock_cond_list_prov_42 = shk_summ42cond_list_prov/15
gen shock1_cond_list_prov_42 = shk_summ412cond_list_prov/16

gen shock_cond_prov_42 = shk_summ42cond_prov/15
gen shock1_cond_prov_42 = shk_summ412cond_prov/16

gen shock_non_cont_prov_42 = shk_summ42non_cont_prov/15
gen shock1_non_cont_prov_42 = shk_summ412non_cont_prov/16

gen shock_non_cond_list_prov_42 = shk_summ42non_cond_list_prov/15
gen shock1_non_cond_list_prov_42 = shk_summ412non_cond_list_prov/16

gen shock_non_cond_prov_42 = shk_summ42non_cond_prov/15
gen shock1_non_cond_prov_42 = shk_summ412non_cond_prov/16

gen shock_constr_42 = shk_summ42constr/15
gen shock1_constr_42 = shk_summ412constr/16

gen shock_permis_42 = shk_summ42permis/15
gen shock1_permis_42 = shk_summ412permis/16
}

if "`y'"=="misc" {
gen shock_prov_42 = shk_summ42prov/1
gen shock1_prov_42 = shk_summ412prov/1

gen shock_word_42 = shk_summ42word/1
gen shock1_word_42 = shk_summ412word/1

gen shock_cont_prov_42 = shk_summ42cont_prov/1
gen shock1_cont_prov_42 = shk_summ412cont_prov/1

gen shock_cond_list_prov_42 = shk_summ42cond_list_prov/1
gen shock1_cond_list_prov_42 = shk_summ412cond_list_prov/1

gen shock_cond_prov_42 = shk_summ42cond_prov/1
gen shock1_cond_prov_42 = shk_summ412cond_prov/1

gen shock_non_cont_prov_42 = shk_summ42non_cont_prov/1
gen shock1_non_cont_prov_42 = shk_summ412non_cont_prov/1

gen shock_non_cond_list_prov_42 = shk_summ42non_cond_list_prov/1
gen shock1_non_cond_list_prov_42 = shk_summ412non_cond_list_prov/1

gen shock_non_cond_prov_42 = shk_summ42non_cond_prov/1
gen shock1_non_cond_prov_42 = shk_summ412non_cond_prov/1

gen shock_constr_42 = shk_summ42constr/1
gen shock1_constr_42 = shk_summ412constr/1

gen shock_permis_42 = shk_summ42permis/1
gen shock1_permis_42 = shk_summ412permis/1
}


if "`y'"=="fisc" {
gen shock_prov_42 = shk_summ42prov/7
gen shock1_prov_42 = shk_summ412prov/8

gen shock_word_42 = shk_summ42word/7
gen shock1_word_42 = shk_summ412word/8

gen shock_cont_prov_42 = shk_summ42cont_prov/7
gen shock1_cont_prov_42 = shk_summ412cont_prov/8

gen shock_cond_list_prov_42 = shk_summ42cond_list_prov/7
gen shock1_cond_list_prov_42 = shk_summ412cond_list_prov/8

gen shock_cond_prov_42 = shk_summ42cond_prov/7
gen shock1_cond_prov_42 = shk_summ412cond_prov/8

gen shock_non_cont_prov_42 = shk_summ42non_cont_prov/7
gen shock1_non_cont_prov_42 = shk_summ412non_cont_prov/8

gen shock_non_cond_list_prov_42 = shk_summ42non_cond_list_prov/7
gen shock1_non_cond_list_prov_42 = shk_summ412non_cond_list_prov/8

gen shock_non_cond_prov_42 = shk_summ42non_cond_prov/7
gen shock1_non_cond_prov_42 = shk_summ412non_cond_prov/8

gen shock_constr_42 = shk_summ42constr/7
gen shock1_constr_42 = shk_summ412constr/8

gen shock_permis_42 = shk_summ42permis/7
gen shock1_permis_42 = shk_summ412permis/7
}


if "`y'"=="proc" {
gen shock_prov_42 = shk_summ42prov/9
gen shock1_prov_42 = shk_summ412prov/10

gen shock_word_42 = shk_summ42word/9
gen shock1_word_42 = shk_summ412word/10

gen shock_cont_prov_42 = shk_summ42cont_prov/9
gen shock1_cont_prov_42 = shk_summ412cont_prov/10

gen shock_cond_list_prov_42 = shk_summ42cond_list_prov/9
gen shock1_cond_list_prov_42 = shk_summ412cond_list_prov/10

gen shock_cond_prov_42 = shk_summ42cond_prov/9
gen shock1_cond_prov_42 = shk_summ412cond_prov/10

gen shock_non_cont_prov_42 = shk_summ42non_cont_prov/9
gen shock1_non_cont_prov_42 = shk_summ412non_cont_prov/10

gen shock_non_cond_list_prov_42 = shk_summ42non_cond_list_prov/9
gen shock1_non_cond_list_prov_42 = shk_summ412non_cond_list_prov/10

gen shock_non_cond_prov_42 = shk_summ42non_cond_prov/9
gen shock1_non_cond_prov_42 = shk_summ412non_cond_prov/10

gen shock_constr_42 = shk_summ42constr/9
gen shock1_constr_42 = shk_summ412constr/10

gen shock_permis_42 = shk_summ42permis/9
gen shock1_permis_42 = shk_summ412permis/10
}


if "`y'"=="soc" {
gen shock_prov_42 = shk_summ42prov/6
gen shock1_prov_42 = shk_summ412prov/7

gen shock_word_42 = shk_summ42word/6
gen shock1_word_42 = shk_summ412word/7

gen shock_cont_prov_42 = shk_summ42cont_prov/6
gen shock1_cont_prov_42 = shk_summ412cont_prov/7

gen shock_cond_list_prov_42 = shk_summ42cond_list_prov/6
gen shock1_cond_list_prov_42 = shk_summ412cond_list_prov/7

gen shock_cond_prov_42 = shk_summ42cond_prov/6
gen shock1_cond_prov_42 = shk_summ412cond_prov/7

gen shock_non_cont_prov_42 = shk_summ42non_cont_prov/6
gen shock1_non_cont_prov_42 = shk_summ412non_cont_prov/7

gen shock_non_cond_list_prov_42 = shk_summ42non_cond_list_prov/6
gen shock1_non_cond_list_prov_42 = shk_summ412non_cond_list_prov/7

gen shock_non_cond_prov_42 = shk_summ42non_cond_prov/6
gen shock1_non_cond_prov_42 = shk_summ412non_cond_prov/7

gen shock_constr_42 = shk_summ42constr/6
gen shock1_constr_42 = shk_summ412constr/7

gen shock_permis_42 = shk_summ42permis/6
gen shock1_permis_42 = shk_summ412permis/7
}

*Standardised Shocks
egen shock_prov42`y' = std(shock_prov_42)
egen shock_word42`y' = std(shock_word_42)
egen shock_cont_p42`y' = std(shock_cont_prov_42)
egen shock_condL42`y' = std(shock_cond_list_prov_42)
egen shock_condP42`y' = std(shock_cond_prov_42)
egen shock_non_cont42`y' = std(shock_non_cont_prov_42)
egen shock_non_condL42`y' = std(shock_non_cond_list_prov_42)
egen shock_non_condP42`y' = std(shock_non_cond_prov_42)
egen shock_constr42`y' = std(shock_constr_42)
egen shock_permis42`y' = std(shock_permis_42)

keep year statefe statename1 state provisions_* word_count_* cont_prov* cond_list* cond_prov* non_cont_prov* non_cond_list* non_cond_prov* constr_obl_* permis_entit_* share`y'* shock_prov42`y' shock_condL42`y' shock_non_condL42`y'

save bartik_data_compl_42_`y'`x', replace

}


************************************ Creating Bartik Instruments - 48 topics *******************************************************



import delimited using "$folder/data/input/state_year_48_all_topics.csv", clear

rename conditional_list_provisions cond_list_prov
rename non_conditional_list_provisions non_cond_list_prov
rename contingent_provisions cont_prov
rename non_contingent_provision non_cont_prov
rename cond_provisions cond_prov
rename non_cond_provisions non_cond_prov

* Currently topics are vertical - must reshape into wide format
drop v1
reshape wide entitlement special_verb entitlement_verb permission permissive_modal neg obligation active_verb strict_modal constraint_value word_count conditional_count conditional conditional_list cond provision cont_prov cond_list_prov cond_prov non_cont_prov non_cond_list_prov non_cond_prov amend repeal, i(state year num_topics) j(topic)



* biennium includes stated year and previous year
gen biennium =  year + mod(year,2)
replace year = biennium

* Creating variables 

foreach x in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 {

egen constr_obl`x'=rowtotal(constraint_value`x' obligation`x'), missing
egen permis_entit`x'=rowtotal(permission`x' entitlement`x'), missing

}
drop constraint_value* obligation* entitlement* permission*


* Collapsing to biennium level

collapse (mean) provision* word_count* cont_prov* cond_list_prov* cond_prov* non_cont_prov* non_cond_list_prov* non_cond_prov* constr_obl* permis_entit* special_verb* permissive_modal* neg* active_verb* strict_modal* amend* repeal*, by(state year)

* Setting time series

egen statefe = group(state)
gen statename1 = state
drop state
gen state = statefe

tsset statefe year, delta(2)

* Crating local macros for all variable combinations and categories

local variables provision0 - permis_entit47

local provisions provision0 - provision47

local words word_count0 - word_count47

local cont_prov cont_prov0 - cont_prov47

local cond_list_prov cond_list_prov0 - cond_list_prov47

local cond_prov cond_prov0 - cond_prov47

local non_cont_prov non_cont_prov0 - non_cont_prov47

local non_cond_list_prov non_cond_list_prov0 - non_cond_list_prov47

local non_cond_prov non_cond_prov0 - non_cond_prov47

local constraint_obligations constr_obl0 - constr_obl47

local permission_entitlements permis_entit0 - permis_entit47


* Replacing missing values with lags

foreach x of varlist `variables' {

replace `x' = L.`x' if missing(`x')
replace `x' = L2.`x' if missing(`x')
replace `x' = L3.`x' if missing(`x')
replace `x' = L4.`x' if missing(`x')
replace `x' = L5.`x' if missing(`x')
}

* Generating log and first difference of all variables

foreach x of varlist `variables' {

gen log_`x' = log(1+`x')
gen growth_48`x' = D.log_`x'

}

* Generating total growth by category-topic and growth in other states

foreach x of varlist  `variables' {

sort year 

by year: egen grow_sum_48`x' = total(growth_48`x')

by year: gen grow_loo_48`x' = (grow_sum_48`x' - growth_48`x') / 49

by year: gen grow_lo1_48`x' = (grow_sum_48`x') / 50

}

*Generating shares of each category and topic

egen provisions_48 = rowtotal(provision0 - provision47)
egen word_count_48 = rowtotal(word_count0 - word_count47)
egen cont_prov_48 = rowtotal(cont_prov0 - cont_prov47)
egen cond_list_prov_48 = rowtotal(cond_list_prov0 - cond_list_prov47)
egen cond_prov_48 = rowtotal(cond_prov0 - cond_prov47)
egen non_cont_prov_48 = rowtotal(non_cont_prov0 - non_cont_prov47)
egen non_cond_list_prov_48 = rowtotal(non_cond_list_prov0 - non_cond_list_prov47)
egen non_cond_prov_48 = rowtotal(non_cond_prov0 - non_cond_prov47)
egen constr_obl_48 = rowtotal(constr_obl0 - constr_obl47)
egen permis_entit_48 = rowtotal(permis_entit0 - permis_entit47)

foreach x of varlist `provisions' {
gen share48_`x' = `x' / provisions_48
}
foreach x of varlist `words' {
gen share48_`x' = `x' / word_count_48
}
foreach x of varlist `cont_prov' {
gen share48_`x' = `x' / cont_prov_48
}
foreach x of varlist `cond_list_prov' {
gen share48_`x' = `x' / cond_list_prov_48
}
foreach x of varlist `cond_prov' {
gen share48_`x' = `x' / cond_prov_48
}
foreach x of varlist `non_cont_prov' {
gen share48_`x' = `x' / non_cont_prov_48
}
foreach x of varlist `non_cond_list_prov' {
gen share48_`x' = `x' / non_cond_list_prov_48
}
foreach x of varlist `non_cond_prov' {
gen share48_`x' = `x' / non_cond_prov_48
}
foreach x of varlist `constraint_obligations' {
gen share48_`x' = `x' / constr_obl_48
}
foreach x of varlist `permission_entitlements' {
gen share48_`x' = `x' / permis_entit_48
}

* Generating average of initial 47 year share

sort statefe year
foreach x of varlist `variables' {

bys statefe: gen topic_in1_`x' = share48_`x'[1] 
bys statefe: gen topic_in2_`x' = share48_`x'[2] 
bys statefe: gen topic_in3_`x' = share48_`x'[3] 
bys statefe: gen topic_in4_`x' = share48_`x'[4] 
bys statefe: gen topic_in5_`x' = share48_`x'[5] 
bys statefe: gen topic_init_`x' = (topic_in1_`x' + topic_in2_`x'+topic_in3_`x'+topic_in4_`x'+topic_in5_`x')/5
}

* Generating Shocks for each category

foreach x of varlist `variables'{
gen shock_sum_48`x' =  topic_init_`x' * grow_loo_48`x'
gen shock_su1_48`x' =  topic_init_`x' * grow_lo1_48`x'

}


egen shk_summ48prov = rowtotal(shock_sum_48prov*)
egen shk_summ472prov = rowtotal(shock_su1_48prov*)

egen shk_summ48word = rowtotal(shock_sum_48word*)
egen shk_summ472word = rowtotal(shock_su1_48word*)

egen shk_summ48cont_prov = rowtotal(shock_sum_48cont_prov*)
egen shk_summ472cont_prov = rowtotal(shock_su1_48cont_prov*)

egen shk_summ48cond_list_prov = rowtotal(shock_sum_48cond_list_prov*)
egen shk_summ472cond_list_prov = rowtotal(shock_su1_48cond_list_prov*)

egen shk_summ48cond_prov = rowtotal(shock_sum_48cond_prov*)
egen shk_summ472cond_prov = rowtotal(shock_su1_48cond_prov*)

egen shk_summ48non_cont_prov = rowtotal(shock_sum_48non_cont_prov*)
egen shk_summ472non_cont_prov = rowtotal(shock_su1_48non_cont_prov*)

egen shk_summ48non_cond_list_prov = rowtotal(shock_sum_48non_cond_list_prov*)
egen shk_summ472non_cond_list_prov = rowtotal(shock_su1_48non_cond_list_prov*)

egen shk_summ48non_cond_prov = rowtotal(shock_sum_48non_cond_prov*)
egen shk_summ472non_cond_prov = rowtotal(shock_su1_48non_cond_prov*)

egen shk_summ48constr = rowtotal(shock_sum_48constr*)
egen shk_summ472constr = rowtotal(shock_su1_48constr*)

egen shk_summ48permis = rowtotal(shock_sum_48permis*)
egen shk_summ472permis = rowtotal(shock_su1_48permis*)


* / divide each category's shock by 48 topics
gen shock_prov_48 = shk_summ48prov/48
gen shock1_prov_48 = shk_summ472prov/48

gen shock_word_48 = shk_summ48word/48
gen shock1_word_48 = shk_summ472word/48

gen shock_cont_prov_48 = shk_summ48cont_prov/48
gen shock1_cont_prov_48 = shk_summ472cont_prov/48

gen shock_cond_list_prov_48 = shk_summ48cond_list_prov/48
gen shock1_cond_list_prov_48 = shk_summ472cond_list_prov/48

gen shock_cond_prov_48 = shk_summ48cond_prov/48
gen shock1_cond_prov_48 = shk_summ472cond_prov/48

gen shock_non_cont_prov_48 = shk_summ48non_cont_prov/48
gen shock1_non_cont_prov_48 = shk_summ472non_cont_prov/48

gen shock_non_cond_list_prov_48 = shk_summ48non_cond_list_prov/48
gen shock1_non_cond_list_prov_48 = shk_summ472non_cond_list_prov/48

gen shock_non_cond_prov_48 = shk_summ48non_cond_prov/48
gen shock1_non_cond_prov_48 = shk_summ472non_cond_prov/48

gen shock_constr_48 = shk_summ48constr/48
gen shock1_constr_48 = shk_summ472constr/48

gen shock_permis_48 = shk_summ48permis/48
gen shock1_permis_48 = shk_summ472permis/48



*Standardised Shocks
egen shock_prov48 = std(shock_prov_48)
egen shock_word48 = std(shock_word_48)
egen shock_cont_prov48 = std(shock_cont_prov_48)
egen shock_cond_list_prov48 = std(shock_cond_list_prov_48)
egen shock_cond_prov48 = std(shock_cond_prov_48)
egen shock_non_cont_prov48 = std(shock_non_cont_prov_48)
egen shock_non_cond_list_prov48 = std(shock_non_cond_list_prov_48)
egen shock_non_cond_prov48 = std(shock_non_cond_prov_48)
egen shock_constr48 = std(shock_constr_48)
egen shock_permis48 = std(shock_permis_48)


keep year statefe statename1 state provisions_* word_count_* cont_prov* cond_list_prov* cond_prov* non_cont_prov* non_cond_list_prov* non_cond_prov* constr_obl_* permis_entit_* share48* shock_prov48 - shock_permis48 growth_48provision* grow_sum_48provision*   share48_provision* growth_48provision*

save bartik_data_compl_48, replace

